﻿using Autofac;
using Autofac.Core;
using Autofac.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Reborn.Infrastructure;
using Reborn.Infrastructure.MediatX;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Reborn.InfrastructureTests
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var builder = new ContainerBuilder();

            builder.RegisterAssemblyTypes(typeof(IMediatorX).GetTypeInfo().Assembly).AsImplementedInterfaces();

            builder
            .RegisterAssemblyTypes(typeof(WebNotification).GetTypeInfo().Assembly)
            .AsClosedTypesOf(typeof(IRouteNotificationHandler<>));

            var services = new ServiceCollection();

            builder.Populate(services);

            var container = builder.Build();
            var serviceProvider = new AutofacServiceProvider(container);

            var mediatorX = serviceProvider.GetRequiredService<IMediatorX>();

            WebNotification webNotification = new WebNotification();
            webNotification.Route = "api/user/get1";

            mediatorX.Publish(webNotification);


        }
    }

    public class WebNotification : IRouteNotification
    {
        public string Route { get; set; }

        public string Response { get; set; }
    }
    public class WebNotificationHandler : IRouteNotificationHandler<WebNotification>
    {
        public string Route => "api/user/get";

        public Task Handle(WebNotification notification, CancellationToken cancellationToken)
        {
            notification.Response = "我草可以哦";
            return Task.CompletedTask;
        }
    }
}
